package java9_23zy;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Test_1 {
    public static void main(String[] args) {
        SAXReader s=new SAXReader();
        try {
            Document r = s.read("D:\\aaa\\src\\java9_23zy\\products.xml");
            Element r1 = r.getRootElement();//获取更目录
            List <Element>l = r1.selectNodes("product");
            for (Element e : l) {
              String itemno= e.selectSingleNode("itemno").getText();
              String name= e.selectSingleNode("name").getText();
              String price= e.selectSingleNode("price").getText();
              String stockcount= e.selectSingleNode("stockcount").getText();
              String unit= e.selectSingleNode("unit").getText();
                System.out.println("编号:"+itemno+"\t名称:"+name+"\t价格"+price+"\t存货:"+stockcount+"\t单位:"+unit);
            }
        } catch (DocumentException e) {
            e.printStackTrace();
        }
    }
}
